package Mouse_key_Event;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;


import Main.Main_Frame;
import Main.mainPanel;
import Main.makeEastPanel;
import Main.westPanel;

public class Key implements KeyListener{
	private Main_Frame CMscreen;
	public static  boolean Stop=true;
	private boolean nopressbutton=false;
	public Key(Main_Frame CMscreen)
	{
		this.CMscreen=CMscreen;//用来调用他的repaint刷新的
	}
	@Override
	public void keyTyped(KeyEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO 自动生成的方法存根
		int key=e.getKeyCode();
		if(nopressbutton) return ;
		nopressbutton=true;
		if(key==32) Stop=!Stop;
		
		if(Stop)
		{
			makeEastPanel.getButton1Stop().setForeground(Color.red);
			return ;
		}else makeEastPanel.getButton1Stop().setForeground(Color.black);
		
		
		if(key==37&&mainPanel.dirction!=2)
		{
			mainPanel.dirction=0;//左
			westPanel.getWestLabel5()[2].setIcon(new ImageIcon("img\\left2.jpg"));
		}else
		{
			westPanel.getWestLabel5()[2].setIcon(new ImageIcon("img\\left.jpg"));
		}
		if(key==38&&mainPanel.dirction!=1)
		{
			mainPanel.dirction=3;//上
			westPanel.getWestLabel5()[0].setIcon(new ImageIcon("img\\up2.jpg"));
		}
		else 
		{
			westPanel.getWestLabel5()[0].setIcon(new ImageIcon("img\\up.jpg"));
		}
		if(key==39&&mainPanel.dirction!=0)
		{
			mainPanel.dirction=2;//右
			westPanel.getWestLabel5()[1].setIcon(new ImageIcon("img\\right2.jpg"));
		}else
		{
			westPanel.getWestLabel5()[1].setIcon(new ImageIcon("img\\right.jpg"));
		}
		if(key==40&&mainPanel.dirction!=3)
		{
			mainPanel.dirction=1;//下
			westPanel.getWestLabel5()[3].setIcon(new ImageIcon("img\\down2.jpg"));
		}else
		{
			westPanel.getWestLabel5()[3].setIcon(new ImageIcon("img\\down.jpg"));
		}
		CMscreen.repaint();
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO 自动生成的方法存根
		nopressbutton=false;
	}

	
	

}
